import { defineStore } from 'pinia'
import { ref, reactive, computed } from 'vue'
/*
export const useCounterStore = defineStore('counters', {
  //变量
  state: () => {
    //data(){}
    return {
      count: 3,
      username: 'zhangchang',
      age: 16,
      user: { id: 23, name: '王大帅哥', job: '拳击手' }
    }
  },
  //函数
  actions: {
    add() {
      this.count++
      this.age += 2
      this.username = '张昌'
    }
  },
  getters: {
    toUpper(): string {
      return `Hello~ ${this.username.toUpperCase()}`
    }
  }
})*/

export const useCounterStore = defineStore('counters', () => {
  //把vue2的 key-value的写法 转成vue3的写法
  const count = ref(3)
  const username = ref('zhangchang')
  const age = ref(18)
  const user = reactive({ id: 23, name: '王大帅哥', job: '拳击手' })

  function add() {
    count.value++
    age.value += 2
    username.value = '张昌'
  }

  const toUpper = computed(() => {
    //return 'BCD'
    return `Hi~ ${username.value.toUpperCase()}`
  })

  return { count, username, age, user, add, toUpper }
})
